package model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

public class Location extends Model
{
	/*
	 * Chigleliin ner
	 */
	private String		name;
	/*
	 * chigleliin code
	 */
	private String		code;
	/*
	 * Cagiin zoruu
	 */
	private int			timeDifference;
	/*
	 * Ulaanbaataraas ene chiglel xurtel nisex tsag
	 */
	private float		flyTime;

	/*
	 * 
	 */
	private Set<Fly>	fliesSrc		= new HashSet<Fly>();
	private Set<Fly>	fliesDst		= new HashSet<Fly>();
	private Set<Fly>	fliesVia		= new HashSet<Fly>();
	private Set<Fly>	fliesCurrent	= new HashSet<Fly>();

	public Location()
	{

	}

	@SuppressWarnings("unchecked")
	public static ArrayList<Location> getAllLocation(Session session)
	{
		Criteria criteria = session.createCriteria(Location.class);
		return (ArrayList<Location>) criteria.list();
	}

	public static String getLocationCode(Session session, Location location)
	{
		Criteria criteria = session.createCriteria(Location.class);
		Criterion criterion = Restrictions.idEq(location.getId());
		criteria.add(criterion);
		location = (Location) criteria.uniqueResult();
		return location.getCode();
	}

	public static String getLocationName(Session session, Location location)
	{
		Criteria criteria = session.createCriteria(Location.class);
		Criterion criterion = Restrictions.idEq(location.getId());
		criteria.add(criterion);
		location = (Location) criteria.uniqueResult();
		return location.getName();
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getCode()
	{
		return code;
	}

	public void setCode(String code)
	{
		this.code = code;
	}

	public int getTimeDifference()
	{
		return timeDifference;
	}

	public void setTimeDifference(int timeDifference)
	{
		this.timeDifference = timeDifference;
	}

	public float getFlyTime()
	{
		return flyTime;
	}

	public void setFlyTime(float flyTime)
	{
		this.flyTime = flyTime;
	}

	public Set<Fly> getFliesSrc()
	{
		return fliesSrc;
	}

	public void setFliesSrc(Set<Fly> fliesSrc)
	{
		this.fliesSrc = fliesSrc;
	}

	public Set<Fly> getFliesDst()
	{
		return fliesDst;
	}

	public void setFliesDst(Set<Fly> fliesDst)
	{
		this.fliesDst = fliesDst;
	}

	public Set<Fly> getFliesVia()
	{
		return fliesVia;
	}

	public void setFliesVia(Set<Fly> fliesVia)
	{
		this.fliesVia = fliesVia;
	}

	public Set<Fly> getFliesCurrent()
	{
		return fliesCurrent;
	}

	public void setFliesCurrent(Set<Fly> fliesCurrent)
	{
		this.fliesCurrent = fliesCurrent;
	}
}